﻿//-----------------------------------------------------------------------------
// <copyright file="Program.cs" company="DCOM Productions">
//     Copyright (c) DCOM Productions.  All rights reserved.
// </copyright>
//-----------------------------------------------------------------------------

namespace BitFlex.Windows.Forms {
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    using BitFlex.Win32;
    using System.Runtime.InteropServices;

    /// <summary>
    /// Windows Explorer ComboBox Control
    /// </summary>
    [ToolboxItem(true)]
    [ToolboxBitmap(typeof(ComboBox))]
    public partial class ExplorerComboBox : ComboBox {
        /// <summary>
        /// Base constructor
        /// </summary>
        public ExplorerComboBox() : base() {
            InitializeComponent();
        }

        #region Platform Invoke

        [DllImport("user32.dll", CharSet = CharSet.Auto)]
        private static extern IntPtr SendMessage(IntPtr hWnd, Int32 msg, IntPtr wParam, string lParam);

        #endregion

        #region Constants

        private const int CB_SETCUEBANNER = 0x1703;

        #endregion

        #region Properties

        private string m_CueText = string.Empty;
        /// <summary>
        /// Gets or sets the Cue Text of the control
        /// </summary>
        [Category("Appearance")]
        [DefaultValue("")]
        [Description("Gets or sets the Cue Text of the control")]
        public string CueText {
            get {
                return m_CueText;
            }
            set {
                m_CueText = value;
                SendMessage(Handle, CB_SETCUEBANNER, IntPtr.Zero, CueText);
            }
        }

        /// <summary>
        /// Gets or sets the index specifying the currently selected item
        /// </summary>
        public override int SelectedIndex {
            get {
                return base.SelectedIndex;
            }
            set {
                base.SelectedIndex = value;
                if (base.SelectedIndex == -1) {
                    SendMessage(Handle, CB_SETCUEBANNER, IntPtr.Zero, CueText);
                }
            }
        }

        #endregion
    }
}